<?php if($this->errMsg) :?>
	<?php $this->showError($this->errMsg)?>
<?php endif; ?>
<?php if($this->msg) :?>		
	<?php $this->showMessage($this->msg)?>	
<?php endif;?>
<form name='form' id='form' action="" method="POST">
	<div class="title_ad"><label><a href="">Sửa câu hỏi khảo sát</a></label>
	</div>
	<div class="mydiv">
	<table  class="tb_box">
		<tr>
			<td>
				<label>Mã Câu hỏi</label>
			</td>
			<td>
				<input type="text" name ="id" value = "<?php echo $this->quest['qid']?>">
			</td>
			<td>
				<label>Ngày Tạo</label>
			</td>
			<td>
				<input readonly="readonly" type="text" name ="qdate" value = "<?php echo $this->quest['qdate']?>">
			</td>
		</tr>
		<tr>
			<td>
				<label>Nội Dung câu hỏi</label>
			</td>
			<td>
				<TEXTAREA Name='qtitle' rows="3" cols="0" style="width: 250px;text-align: left;"><?php echo $this->quest['qtitle']?></TEXTAREA> 
			</td>
			<td>
				<label>Các tin hiển thị</label>
			</td>
			<td id="arrnews">
				<a href='javascript:addnews()' title='Add News' class='tool-16 add'></a>
				<?php 
				foreach ($this->quest['news'] as $key=>$row)
				{
					echo("<div id='news".$key."'>");
					echo('<select name="news_id[]">');
					echo $this->Options($this->arrNews,$row->id);
					echo("</select>&nbsp<a href='javascript:del($key)' title='Delete' class='tool-16 delete'></a>");
					echo("<br/>");
					echo("</div>");
				}
				?>
			</td>
		</tr>
	</table>
	<div id="listanswer">
	<h3 style='color: #325B6D;'>Danh sách các lựa chọn &nbsp;<a href='javascript:addAnswer()' title='Add Answer' class='tool-24 add'></a></h3>
	<?php echo $this->listanswer($this->quest['answer']);?>
	</div>
		<div class="div_button" >	
			<input type="submit" value="Lưu" class="button"/>
			<input type="reset" value="Làm lại" class="button" />
		</div>
	</div>
</form>
<script>
function del(key)
{
	if(!confirm("Bạn muốn gỡ câu hỏi khỏi tin này không?"))
		return false;
	$("#news"+key).remove();
}
function addnews()
{
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/news/listnews'?> ",
		dataType: 'json',
		success: function(msg){
			if(msg)
			{
				var count = $('select').length;
				var select = "";
				select += "<div id='news"+count+"'>";
				select += '<select name="news_id[]">';
				select +="<option>Chọn tin</option>";
				$.each(msg, function(key, value) { 
					select +="<option value='"+value.id+"'>"+value.headLines+"</option>"; 
				});
				select += "</select>&nbsp<a href='javascript:del("+count+")' title='Delete' class='tool-16 delete'></a>";
				select += "<br/>";
				select += "</div>";
				$('#arrnews').append(select);
			}else
				alert('Error');
		}
	});
}

function addAnswer()
{
	var count = $('legend').length;
	var strList = "<fieldset id='con_"+count+"'><legend>Lựa chọn "+(count+1)+"&nbsp<a href='javascript:delAnswer("+count+")' title='Delete' class='tool-16 delete'></a></legend>";
	strList += "<table>";
	strList += "	<tr>";
	strList += "		<td><label>Mã lựa chọn</label></td>";
	strList += "		<td colspan='3'><TEXTAREA Name='atitle[]' rows='3' cols='0' style='width: 250px;text-align: left;'></TEXTAREA> </td>";
	strList += "		<td><label>Số lần chọn</label></td>";
	strList += "		<td><input readonly type='text' name ='acount[]' value = '0'></td>";
	strList += "	</tr>";
	strList += "</table>";
	strList +="</fieldset>";
	
	$('#listanswer').append(strList);
}

function delAnswer(key)
{
	if(!(confirm("Bạn muốn xóa lựa chọn này?")))
		return;
	$('#con_'+key).remove();
}
</script>